﻿// CParsSetDlg.cpp: 实现文件
//

#include "pch.h"
#include "RTOC-Data-Interface.h"
#include "CParsSetDlg.h"
#include "afxdialogex.h"


// CParsSetDlg 对话框

IMPLEMENT_DYNAMIC(CParsSetDlg, CDialogEx)

CParsSetDlg::CParsSetDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_PARSSETDLG, pParent)
{

}

CParsSetDlg::~CParsSetDlg()
{
}

void CParsSetDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_GridControl(pDX, IDC_GRID1, m_Grid);
}


BEGIN_MESSAGE_MAP(CParsSetDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &CParsSetDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// CParsSetDlg 消息处理程序


BOOL CParsSetDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	CString strTemp;
	m_Grid.SetRowCount(MAXPARNUMS + 1);
	m_Grid.SetColumnCount(6);
	m_Grid.SetFixedColumnCount(1);
	m_Grid.SetFixedRowCount(1);
	m_Grid.SetItemText(0, 0, _T("序号"));
	m_Grid.SetItemText(0, 1, _T("metricCode"));
	m_Grid.SetItemText(0, 2, _T("metricName"));
	m_Grid.SetItemText(0, 3, _T("一体化字段名"));
	m_Grid.SetItemText(0, 4, _T("中心库字段名"));
	m_Grid.SetItemText(0, 5, _T("KD字段名"));

	for (int i = 0; i < MAXPARNUMS; i++)
	{
		strTemp.Format(_T("ID%03d"), i + 1);
		m_Grid.SetItemText(i + 1, 0, strTemp);
		m_Grid.SetItemText(i + 1, 1, gl.pi.metricCode[i]);
		m_Grid.SetItemText(i + 1, 2, gl.pi.metricName[i]);
		m_Grid.SetItemText(i + 1, 3, gl.pi.strFieldName[i]);
		m_Grid.SetItemText(i + 1, 4, gl.pi.strZxkFieldName[i]);
		m_Grid.SetItemText(i + 1, 5, gl.pi.strKDFieldName[i]);
	}
	m_Grid.AutoSize();

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CParsSetDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	CString strTemp, strBuf;
	for (int i = 0; i < MAXPARNUMS; i++)
	{
		strTemp = m_Grid.GetItemText(i + 1, 1);
		strTemp.Trim();
		gl.pi.metricCode[i] = strTemp;
		strTemp = m_Grid.GetItemText(i + 1, 2);
		strTemp.Trim();
		gl.pi.metricName[i] = strTemp;
		strTemp = m_Grid.GetItemText(i + 1, 3);
		strTemp.Trim();
		gl.pi.strFieldName[i] = strTemp;
		strTemp = m_Grid.GetItemText(i + 1, 4);
		strTemp.Trim();
		gl.pi.strZxkFieldName[i] = strTemp;
		strTemp = m_Grid.GetItemText(i + 1, 5);
		strTemp.Trim();
		gl.pi.strKDFieldName[i] = strTemp;
	}

	//保存配置
	for (int i = 0; i < MAXPARNUMS; i++)
	{
		strTemp.Format(_T("ID%03d"), i);
		if (gl.pi.metricName[i] == _T(""))
			strBuf=_T("");
		else
			strBuf.Format(_T("%s;%s;%s;%s;%s"), gl.pi.metricName[i], gl.pi.metricCode[i], gl.pi.strFieldName[i], gl.pi.strZxkFieldName[i],gl.pi.strKDFieldName[i]);
		SaveINI(_T("PARS"), strTemp, strBuf);
	}
	CDialogEx::OnOK();
}
